<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            margin: 10px;
        }

        h4 span {
            color: skyblue;
            font-size: 22px;
        }

        .input-box {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .input-box span {
            color: skyblue;
        }

        .input-box input {
            height: 30px;
            width: 85%;
            border: none;
            background-color: rgba(128, 128, 128, 0.134);
            border-radius: 30px;
        }

        .search {
            margin: 20px 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .search span {
            font-size: 14px;
            font-weight: 800;

        }

        .search button {
            border: none;
            background-color: white;
        }

        .search .content {
            height: 30px;
            color: gray;
        }

        .faxian {
            display: block;
            margin-top: 30px;
            margin-bottom: 10px;
            font-size: 14px;
            font-weight: 800;
        }

        .bottom div {
            height: 25px;
            background-color: rgb(181, 179, 179);
            margin: 10px;
            text-align: center;
            line-height: 25px;
            padding: 5px;
            font-size: 14px;
        }

        .bottom {
            display: flex;
            flex-wrap: wrap;
        }
    </style>
</head>

<body>
    <div id="app">
        <h4><span><</span>&emsp;搜索</h4>
        <div class="input-box">
            <input type="text" placeholder="搜索商家、商品名称" v-model="inputText">
            <span @click="add">搜索</span>
        </div>
        <div class="search">
            <span>历史搜索</span>
            <button @click="del(index)">删除</button>
        </div>
        <div v-for="(item,index) in tasklist" :key="index">
            <div class="content">{{item.name}}</div>
        </div>
        <span class="faxian">搜索发现</span>
        <div class="bottom">
            <div>麻辣烫</div>
            <div>米线</div>
            <div>披萨</div>
            <div>蛋糕</div>
            <div>汉堡</div>
            <div>腊八粥</div>
            <div>烤肉拌饭</div>
            <div>炸鸡</div>
            <div>味多美(正宁路店)</div>
        </div>

    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',//保存输入框中的值
            tasklist: [

            ]
        },
        methods: {
            add() { //添加任务
                if (this.inputText) { //输入框不为空, 才添加任务
                    //构造一个任务对象
                    var obj = { id: this.tasklist.length + 1, name: this.inputText};
                    //将任务对象 添加到任务列表中
                    this.tasklist.push(obj);
                    //清空输入框
                    this.inputText = '';
                }
            },
            del(index) {
                this.tasklist.splice(index, 1)
            }
        }
    })
</script>